package zqkcom.atguigu.dao.impl;

import zqkcom.atguigu.bean.Order;
import zqkcom.atguigu.dao.BaseDao;
import zqkcom.atguigu.dao.OrderDao;

import java.util.List;
import java.util.stream.Stream;

public class OrderDaoImpl extends BaseDao<Order> implements OrderDao {

    @Override
    //保存订单
    public void saveOrder(Order order) {
        String sql = "insert into bs_order values(?,?,？,?,?,?)";
        update(sql, order.getId(), order.getCreateTime(), order.getTotalCount(), order.getTotalAmount(), order.getStatus(), order.getUserId());
    }

    @Override
    ///获取我的订单
    public List<Order> getMyOrder(Integer userId) {
        String sql = "select * from bs_order where userId = ?";
        return getBeanList(Order.class, sql, userId);
    }

    @Override
    //获取所有订单信息
    public List<Order> getAllOrder() {
        String sql = "select * from bs_order";
        return getBeanList(Order.class, sql);
    }

    @Override
    //更新订单
    public void updateStatus(String orderId, Integer status) {
        String sql = "update bs_order set status=? and id =?";
        update(sql,status,orderId);
    }
}
